package com.mstarc.app.mnfc.mstarcApiUtils;

import android.util.Log;

import java.util.Formatter;

/**
 * @author 崔健伟
 * @version V1.0
 * @Title: BytetohexStringUtil.java
 * @Package com.mstarc.app.mnfc.mstarcApiUtils
 * @Description:
 * @date 2017/6/21 10:53
 */
public class BytetohexStringUtil {
    public static String BytetohexString(int[] b) {
        StringBuilder sb = new StringBuilder(b.length * (2 + 1));
        Formatter formatter = new Formatter(sb);
        String sb2 = "";
        int len = b.length;
        for (int i = 0; i < len; i++) {
//            byte i_b = (byte) (((byte) b[i]) & 0xFF);
            byte i_b = (byte) b[i];
            //i_b=i_b&&0xff;
            if (i < len - 1)
                formatter.format("%02X:", i_b);
            else
                formatter.format("%02X", i_b);

            sb2 += "," + b[i];
        }
        formatter.close();
//        Log.d("MainActivity", "转换" + sb2);
        return sb.toString();
    }

    public static String BytetohexStringForDecimal(int[] b) {
        String sb2 = "";
        int len = b.length;
        for (int i = 0; i < len; i++) {
            sb2 += b[i];
        }
        return sb2;
    }
}
